import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { UserEntity } from './user.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { UserStatus } from './constant';

@Injectable()
export class UserService {
  constructor(
    @InjectRepository(UserEntity)
    private readonly userRepository: Repository<UserEntity>
  ) {}
  // 查询用户列表
  list() {
    return this.userRepository.find();
  }
  // 根据用户名查询用户
  async findUserByUserName(username: string) {
    return this.userRepository.findOne({
      where: {
        username,
        status: UserStatus.Enabled
      }
    });
  }
}
